# Bar System 服务停止脚本

$ErrorActionPreference = "Continue"

Write-Host "停止Bar System服务..." -ForegroundColor Cyan

# 停止后端服务 (Node.js进程监听38521端口)
Write-Host "停止后端服务..." -ForegroundColor Yellow
$backendProcesses = Get-NetTCPConnection -LocalPort 38521 -ErrorAction SilentlyContinue | 
    Select-Object -ExpandProperty OwningProcess | 
    Get-Process -Id {$_} -ErrorAction SilentlyContinue

if ($backendProcesses) {
    $backendProcesses | Stop-Process -Force
    Write-Host "后端服务已停止" -ForegroundColor Green
} else {
    Write-Host "后端服务未运行" -ForegroundColor Gray
}

# 停止Web前端服务 (Node.js进程监听35280端口)
Write-Host "停止Web前端服务..." -ForegroundColor Yellow
$webProcesses = Get-NetTCPConnection -LocalPort 35280 -ErrorAction SilentlyContinue | 
    Select-Object -ExpandProperty OwningProcess | 
    Get-Process -Id {$_} -ErrorAction SilentlyContinue

if ($webProcesses) {
    $webProcesses | Stop-Process -Force
    Write-Host "Web前端服务已停止" -ForegroundColor Green
} else {
    Write-Host "Web前端服务未运行" -ForegroundColor Gray
}

Write-Host "`n所有服务已停止" -ForegroundColor Cyan
